import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push
    //修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const routes = [{
        path: '/',
        //name: 'index',
        component: () =>
            import ('../views/index.vue'),
        children: [{
                path: '/',
                redirect: '/home',
            },
            {
                path: '/home',
                name: 'home',
                component: () =>
                    import ('../views/home.vue')
            },
            {
                path: '/order',
                name: 'order',
                component: () =>
                    import ('../views/order.vue')
            },
            {
                path: '/me',
                name: 'me',
                component: () =>
                    import ('../views/me.vue')
            },
            {
                path: '/vaddress',
                name: 'vaddress',
                component: () =>
                    import ('../views/vaddress.vue')
            },
            {
                path: '/selectCity',
                name: 'selectCity',
                component: () =>
                    import ('../views/selectCity.vue')
            },
            {
                path: '/search',
                name: 'search',
                component: () =>
                    import ('../views/search.vue')
            },
            {
                path: '/shop',
                name: 'shop',
                redirect: '/goods',
                component: () =>
                    import ('../views/Shops/shop.vue'),
                children: [{
                        path: '/goods',
                        name: 'goods',
                        component: () =>
                            import ('../views/Shops/goods.vue')
                    },
                    {
                        path: '/comments',
                        name: 'comments',
                        component: () =>
                            import ('../views/Shops/comments.vue')
                    },
                    {
                        path: '/seller',
                        name: 'seller',
                        component: () =>
                            import ('../views/Shops/seller.vue')
                    },
                ]
            },
            {
                path: '/myAddress',
                name: 'myAddress',
                component: () =>
                    import ('../views/Order/myAddress.vue')
            }, {
                path: '/addAddress',
                name: 'addAddress',
                component: () =>
                    import ('../views/Order/addAddress.vue')
            },
            {
                path: '/settlement',
                name: 'settlement',
                component: () =>
                    import ('../views/Order/settlement.vue')
            },
            {
                path: '/remark',
                name: 'remark',
                component: () =>
                    import ('../views/Order/remark.vue')
            },
            {
                path: '/pay',
                name: 'pay',
                component: () =>
                    import ('../views/Order/pay.vue')
            },
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ('../views/login.vue')
    }
]

const router = new VueRouter({
    routes,
    mode: 'hash',
    linkActiveClass: "active",
})


export default router